#!/bin/bash

# Package name of your app
#PACKAGE="com.example.empty_view"
PACKAGE="io.flutter.examples.hello_world"
#PACKAGE="com.example.flutter_helloworld"
adb shell am force-stop ${PACKAGE}
sleep 1s

script_dir=$(dirname "$(realpath "$0")")
timestamp=$(date +"%H%M_%S")
mkdir -p ${timestamp}
# Output log file
LOGFILE="${timestamp}/meminfo_log.txt"

echo "Capturing PSS memory info for $PACKAGE every 1 second for 5 seconds..."
echo "Results will be saved in $LOGFILE"
adb shell monkey -p ${PACKAGE} -c android.intent.category.LAUNCHER 1
for i in {1..5}; do
    # Get current timestamp
    TIMESTAMP=$(date +"%Y-%m-%d %H:%M:%S")

    # Capture dumpsys meminfo and extract TOTAL PSS line
    PSS=$(adb shell dumpsys meminfo $PACKAGE | grep "TOTAL PSS" | awk '{print $3}')

    # Write to log file with timestamp
    echo "$TIMESTAMP $PSS" >> $LOGFILE
    echo "$PSS"

    # Wait 1 second before next iteration
    sleep 1
done

echo "Done! Check $LOGFILE for results."

